<?php
class Debug{
	static $arOut=array();

	static function log( $errno, $errstr, $errfile='', $errline='' ) {

		switch ( $errno ) {
			case E_NOTICE:
			case E_USER_NOTICE:
				$errors = "Notice";
				break;
			case E_WARNING:
			case E_USER_WARNING:
				$errors = "Warning";
				break;
			case E_ERROR:
			case E_USER_ERROR:
				$errors = "Fatal Error";
				break;
			case 8192:
			case 16384:
				$errors = "Deprecated";
				break;
			default:
				$errors = "Unknown";
				break;
		}

	
		self::$arOut[] = debug_backtrace();//sprintf("\n<b>%s</b>: %s in <b>%s</b> on line <b>%d</b><br />\n", $errors, $errstr, $errfile, $errline);
		//myPrint( debug_backtrace(), 'debug_backtrace: ');
		return count( self::$arOut );
	}
	
	static function localError( $ermess, $errno = E_WARNING ) {
		$errn = self::log( $errno, $ermess, __FILE__, __LINE__); 
		return '<b style="color:red">'.$errn.' WARNING! '.$ermess.'</b>';
	}
	
	static function Out() {
		$out='';
		$cnt = count( self::$arOut);
		if($cnt>0){	
			foreach( self::$arOut as $debug ) {
				ob_start(); 
					myPrint($debug, $debug[0]['args'][1].' ( '.$debug[0]['file'].' in line '.$debug[0]['line'].' )' ); $myPrint=ob_get_contents();
				ob_end_clean();
				$out.='<li>'.$myPrint.'</li>';
			}
			$out='<fieldset><legend>'.$cnt.' Debugs: </legend><ol>'.$out.'</ol></fieldset>';		
		} 
		return $out;
	}
}
?>